package com.lee.thread;


class NumThread implements Runnable {
	 
	private  int num = 5;
	
	@Override
	public  void run() {
		
		synchronized (this) {
		while (true) {
			
				if (num>0) {
					try {
						Thread.sleep(100);
						System.out.println(Thread.currentThread().getName() +" "+(num--));
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					System.out.println(Thread.currentThread().getName() +"退出了");
					break;
				}
			}
		}
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}
}


public class ThreadTest4 {
	public static void main(String[] args) {
		NumThread t = new NumThread();
		new Thread(t).start();
		new Thread(t).start();
	}
	
}
